package com.lzh.seatrend.util.commonsbeanutils;

import org.apache.commons.beanutils.MethodUtils;
import org.junit.Test;

import java.lang.reflect.Method;

public class MethodUtilsTest {
    @Test
    public void test() throws Exception{
        UserInfo userInfo = new UserInfo();
        // 1.通过方法名和参数类型获得可访问方法
        Method method = MethodUtils.getAccessibleMethod(UserInfo.class, "setUserId", String.class);
        method.invoke(userInfo,"lzh");
        // 2.可以直接通过invokeMethod执行方法
        MethodUtils.invokeMethod(userInfo, "setUserName", "刘子昊");
        System.out.println(userInfo);
    }
}
